from fastapi import FastAPI, HTTPException, Request
from fastapi.responses import JSONResponse
from typing import List
import asyncio
import aiohttp
import time
import openai

def ChatgptOpenAI(msg):  #文心一言需要付费

    msg = msg + "所有的回答在100字以内"
    # optional; defaults to `os.environ['OPENAI_API_KEY']`
    openai.api_key = "fastgpt-h6hAxmwwt3emzux1dSe8gXGI0wDpG0scL5nlPicGMpvHas2DpqXi"

    # all client options can be configured just like the `OpenAI` instantiation counterpart
    openai.base_url = "http://127.0.0.1:8000/process"
    openai.default_headers = {"x-foo": "true"}

    completion = openai.chat.completions.create(
        model="deepseek-r1:14b",
        messages=[
            {
                "role": "user",
                "content": msg,
            },
        ],
    )
    #print(completion.choices[0].message.content)
    return completion.choices[0].message.content
    # 正常会输出结果：Hello there! How can I assist you today ?

if __name__ == "__main__":

    line = "你好,1+1等于几，你今天过得怎么样"
    reply = ChatgptOpenAI(line)
    print(f"reply: {reply}")

